package io.renren.modules.generator.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.generator.dao.TTrainingCheckDao;
import io.renren.modules.generator.entity.TTrainingCheckEntity;
import io.renren.modules.generator.service.TTrainingCheckService;


@Service("tTrainingCheckService")
public class TTrainingCheckServiceImpl extends ServiceImpl<TTrainingCheckDao, TTrainingCheckEntity> implements TTrainingCheckService {

    @Autowired
    private TTrainingCheckDao trainingCheckDao;
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<TTrainingCheckEntity> page = this.page(
                new Query<TTrainingCheckEntity>().getPage(params),
                new QueryWrapper<TTrainingCheckEntity>()
        );

        return new PageUtils(page);
    }

    /**
     * 新增  考核信息
     */
   public Integer insertTTrainingCheck(TTrainingCheckEntity trainingCheckEntity){
       trainingCheckDao.insertTTrainingCheck(trainingCheckEntity);
       Integer id=trainingCheckEntity.getId();
        return id;
    }
    /**
     * 获取最新一条的数据
     */
    public TTrainingCheckEntity getNewInfo(){
        return trainingCheckDao.getNewInfo();
    }

    /**
     * 根据训练ID和考核次数查询考核记录
     * @param trainingId
     * @param chenkCount
     * @return
     */
    public  TTrainingCheckEntity selectByTrainingIdAndCount(Integer trainingId,Integer chenkCount){
        return trainingCheckDao.selectByTrainingIdAndCount(trainingId,chenkCount);
    }

    public List<TTrainingCheckEntity> selectByTrainingId(Integer trainingId){
        return trainingCheckDao.selectByTrainingId(trainingId);
    }

    /**
     * 更新考核记录
     * @param trainingCheckEntity
     * @return
     */
    public int updateTrainingCheck(TTrainingCheckEntity trainingCheckEntity){
        return trainingCheckDao.updateByPrimaryKeySelective(trainingCheckEntity);
    }

}